var wxRequest = require('../../utils/wxRequest')
var WxParse = require('../../plugins/wxParse/wxParse.js');
var Common = require('../../utils/common');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    noticeInfo:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.init(this);

    if(options.type == "index"){
      app.api.clientPublic_getIndexAnnouncementDes({
        id: options.id,
      },(res)=>{
        console.log(res)
        WxParse.wxParse('content', 'html', res.data.content, this, 5);
        this.setData({
          noticeInfo: res.data
        });
      })
      return false;
    }

    var noticeId = options.id;
    
    //获取公告详情
    var url = app.globalData.domain + "/client/user/getAnnouncementDes";
    var parm = {
      token: wx.getStorageSync("token"),
      id: options.id,
      type: options.type
    }
    wxRequest.postRequest(url, parm).then(res => {
      console.log("公告详情=>", res);
      res.data.createTime = res.data.createTime.replace(/-/g, "/").substring(0, 16);
      this.setData({
        noticeInfo: res.data
      });
      if (this.data.noticeInfo != null){
        var url = app.globalData.domain + "/client/user/readAnnouncement";
        var parm = {
          token: wx.getStorageSync("token"),
          idAnnouncement: this.data.noticeInfo.id,
          type: 2
        }
        wxRequest.postRequest(url, parm).then(res => {
          console.log("已经读=>", res);
        }, error => {
          // Common.showToast(error);
        });
      }
    }, error => {
      Common.showToast(error);
    });


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },



})